package com.example.spidertp.core.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.spidertp.core.SpiderThreadPool;
import com.example.spidertp.core.mapper.TpLifecycleMapper;
import com.example.spidertp.core.model.enums.TpLifecycleTypeEnum;
import com.example.spidertp.core.model.entity.TpLifecycle;
import com.example.spidertp.core.service.TpLifecycleService;
import com.example.spidertp.utils.DateUtils;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @author xiong.bo
 * @version 1.0
 * @date 2022/9/24 4:58 下午
 */

@Service
public class TpLifecycleServiceImpl extends ServiceImpl<TpLifecycleMapper, TpLifecycle>
        implements TpLifecycleService {


    @Override
    public void createTpRecord(String poolName, SpiderThreadPool threadPool, TpLifecycleTypeEnum typeEnum) {
        TpLifecycle lc = new TpLifecycle();
        lc.setPoolName(poolName);
        lc.setCorePoolSize(threadPool.getCorePoolSize());
        lc.setMaximumPoolSize(threadPool.getMaximumPoolSize());
        lc.setKeepAliveTime(threadPool.getKeepAliveTime(TimeUnit.SECONDS));
        lc.setDataType(typeEnum.getCode());
        lc.setDataTypeDesc(typeEnum.getName());
        lc.setCreateTime(DateUtils.getCurrentTimestamp());
        lc.setCreateUser("admin");//替换为当前用户
        this.save(lc);
    }

}
